import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import Login from './views/admin/auth/login.vue'
import index from './views/index.vue'
import notfound from './views/admin/404.vue'
import faultlist from './views/fault/list.vue'
import faultsort from './views/fault/sort.vue'
import falutsolvelist from './views/fault/solvelist.vue'
import repairadd from './views/repair/add.vue'
import repairlist from './views/repair/list.vue'
import repairpartadd from './views/repair/partadd.vue'
import repairpartuse from './views/repair/partuse.vue'
import reportedadd from './views/reported/add.vue'
import reportedall from './views/reported/all.vue'
import userlist from './views/user/list.vue'
import useradd from './views/user/add.vue'
import userupd from './views/user/upd.vue'
import locationlist from './views/location/list.vue'
import locationadd from './views/location/add.vue'
import columnslist from './views/columns/list.vue'
import columnsadd from './views/columns/add.vue'
import columnsupd from  './views/columns/updlist.vue'
import columnallocat from './views/columns/allocat.vue'
import reportedlist from './views/reported/list.vue'


Vue.use(Router)

const router= new Router({
    mode:'history',
  routes: [

      {
          path: '/home',
          name: 'Home',
          component: Home
       },
      {
          path: '/',
          name: 'Login',
          component: Login
      },
      {
          path: '/index',
          name: 'index',
          component: index,
          children: [
              { path: '/repair/add', name: 'repairadd', component: repairadd },
              { path: '/repair/list', name: 'repairlist', component: repairlist },
              { path: '/repair/partadd', name: 'repairpartadd', component: repairpartadd },
              { path: '/repair/partuse', name: 'repairpartuse', component: repairpartuse },
              { path: '/reported/add', name: 'reportedadd', component: reportedadd },
              { path: '/reported/all', name: 'reportedall', component: reportedall },
              { path: '/reported/list', name: 'reportedlist', component: reportedlist },
              { path: '/fault/list', name: 'faultlist', component: faultlist },
              { path: '/fault/sort', name: 'faultsort', component: faultsort },
              { path: '/location/add', name: 'locationadd', component: locationadd },
              { path: '/location/list', name: 'locationlist', component: locationlist },
              { path: '/user/add', name: 'useradd', component: useradd },
              { path: '/user/list', name: 'userlist', component: userlist },
              { path: '/columns/add', name: 'columnsadd', component: columnsadd },
              { path: '/columns/list', name: 'columnslist', component: columnslist },
              { path: '/user/upd/:id', name: 'userupd', component: userupd },
              { path: '/fault/solvelist/:id', name: 'falutsolvelist', component: falutsolvelist },
              { path: '/columns/upd/:id', name: 'columnsupd', component: columnsupd },
              { path: '/columns/allocat/:id', name: 'columnallocat', component: columnallocat },
          ]
      },
      {
          path:'/*',
          name:'notfound',
          component:notfound
      }
  ]
})


//路由守卫
router.beforeEach((to,from,next)=>{
    const isLogin= true;

    if (to.path=="/")
    {
        next();
    }
    else {
        isLogin ?next() : next('/')
    }
   next();

    }
)

export default router;
